<?php
/**
 *
 * $Rev::				$:  Revision of last commit
 * $Author::	        $:  Author of last commit
 * $Date:: 				$:  Date of last commit
 *
 */

require_once './inc/config.inc.php';
require_once './lib/Database.class.php';
require_once './lib/Student.class.php';

require_once './lib/DoS.class.php';

// @todo: take out.  Session should already have been initiated

if (!isset($_SESSION)) {
	session_start();
}

if (isset($_GET['userid'])) {
	$_SESSION['userid'] = $_GET['userid'];
}

if (isset($_GET['USN'])) {
	$student = new Student($_GET['USN']);
	if (isset($_POST['status'])) {
		if ($response = $student->setStatus($_POST['status'])) {
			$highlights[] = "Registration has been updated";
		} else {
			$errors[] = "Registration failed";
		}
	}
}

$dos = new DoS($_SESSION['userid']);

include_once './inc/header.inc.php';

?>

<h1>You're logged in as: <?php print $dos->getName() ."(".$_SESSION['userid'].")" ?></h1>

<?php

if (isset($student)) {
	print $student->getTableDetails(array("USN","STR_PreferredName AS 'Preferred Name'","Surname","STR_CRSID AS crsID","Email"));
	print $student->dosForm($_GET['USN']);
} else {
	?>
<table id="dos">
	<thead>
		<tr>
			<th>USN</th>
			<th>Name</th>
		</tr>
	</thead>
	<tbody>
	<?php foreach ($dos->getAssocStudents() as $USN => $student_name) { ?>
		<tr id="<?php print $USN ?>">
			<td><a href="dos.php?USN=<?php print $USN ?>" title="<?php print $student_name ?>"><?php print $USN ?></a></td><td><?php print $student_name?></td>
		</tr>
	<?php }?>
	</tbody>
</table>
<?php
}
?>
<script type="text/javascript" src="js/dos.js" />
</body>
</html>
